//
//  TDCarSourceListC.m
//  TBRentClient
//
//  Created by tonbright on 2018/6/7.
//  Copyright © 2018年 tonbright. All rights reserved.
//
static NSString *rowNum = @"4";
#import "TDCarSourceListC.h"
#import "TDSearchCarListCell.h"
#import "TDSearchStoreC.h"
#import "TDChooseCarC.h"
#import "TDCarDetailC.h"
#import "TDriveCarDatePicker.h"
#import "PopoverView.h"
#import "UIView+ZLExtension.h"

#import "TDCarSourceSectionHeadView.h"
#import "TDCarSourceListHeadView.h"

#import "TDSearchCarController.h"

#import "NetWorkRequest.h"
#import "LocationHelper.h"

#import "TDChooseCarModel.h"
#import "TDCarSourceModel.h"
#import "TDSearchStoreModel.h"
@interface TDCarSourceListC ()<TDCarSourceListHeadViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UITextField *tf_search;

@property (weak, nonatomic) IBOutlet UIView *nav_view;
@property (weak, nonatomic) IBOutlet UIView *view_c1;
@property (weak, nonatomic) IBOutlet UIView *view_c2;
@property (weak, nonatomic) IBOutlet UIView *view_c3;

@property (nonatomic, assign) NSInteger selIndex;

@property (weak, nonatomic) IBOutlet UIView *view_selectTiaoJian;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;

@property (nonatomic,strong)NSMutableArray *titleArray;
@property (nonatomic,copy)NSString *selCarDesStr;
@property (nonatomic,copy)NSString *selDateDesStr;
@property (nonatomic,copy)NSString *selStoreDesStr;
@property(nonatomic,assign)CGFloat historyOffY;

@property (nonatomic,strong)TDCarSourceSectionHeadView *carSourceSectionHeadView;
@property (nonatomic,strong)TDCarSourceListHeadView *carSourceListHeadView;

@property (nonatomic,strong)NSIndexPath *leftSelCarIndex;
@property (nonatomic,strong)NSIndexPath *rightSelCarIndex;

@property (nonatomic,strong)TDChooseSelectedModel *selCarModel;//选中的车辆数据
@property (nonatomic,strong)TDDriveCarDatePickerSelModel *selDateModel;//选中的日期数据
@property (nonatomic,strong)TDSearchStoreSelModel *selStoreModel;//选中的店模型

@property (nonatomic,strong)NSMutableArray *carListArray;
@property (nonatomic,copy)NSString *totalCarNum;

@end

@implementation TDCarSourceListC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    //开始定位--------
    [self loadData];
}

- (void)setupUI {
    //添加tableView
    self.view.backgroundColor = [UIColor whiteColor];
    _nav_view.layer.borderWidth = 1;
    _nav_view.layer.borderColor = [UIColor lightGrayColor].CGColor;
//    [self setBtnColor:_btn_chooseCar];
//    [self setBtnColor:_btn_chooseDate];
//    [self setBtnColor:_btn_chooseStore];
    
    [self setupTableView];
    self.carSourceListHeadView = [TDCarSourceListHeadView carSourceListHeadView];
    [self.view addSubview:self.carSourceListHeadView];

}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    self.carSourceListHeadView.delegate = self;
  
//    self.carSourceListHeadView.frame = CGRectMake(0, 71, Width, 66);
    [self.view bringSubviewToFront:_nav_view];
    [self.view bringSubviewToFront:_view_c1];
    [self.view bringSubviewToFront:_view_c2];
    [self.view bringSubviewToFront:_view_c3];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSMutableArray *marr = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
    for (UIViewController *vc in marr) {
        if ([vc isKindOfClass:[TDSearchCarController class]]) {
            [marr removeObject:vc];
            break;
        }
    }
    self.navigationController.viewControllers = marr;
}


- (void)carSourceListHeadViewBtnClick:(NSInteger)tag {
    [self chooseCarBtnClick:tag];
}

// MARK: - 顶部按钮点击事件---------------
- (void)chooseCarBtnClick:(NSInteger)type {
    if (type == 0) {
        [self alertChooseCarBrandC];
    }else if (type == 1) {
        [self chooseDate];
    }else {
        [self chooseStore];
    }
}

// MARK: - 选择车辆--------------
- (void)alertChooseCarBrandC {
    TDChooseCarC *chooseCar = [[TDChooseCarC alloc] init];
    
    chooseCar.tf_search_str = self.tf_search.text;
    chooseCar.locationModel = self.locationModel;
//    chooseCar.selModel = self.selCarModel;
    chooseCar.selDateModel = self.selDateModel;
    chooseCar.selStoreModel = self.selStoreModel;
    
    chooseCar.selLeftIndexPath = self.leftSelCarIndex;
    chooseCar.selRightIndexPath = self.rightSelCarIndex;
    [self addChildViewController:chooseCar];
    [self.view addSubview:chooseCar.view];
    chooseCar.view.frame = CGRectMake(0, Height, Width, Height);
    [UIView animateWithDuration:0.3f animations:^{
        chooseCar.view.frame = CGRectMake(0, 0, Width, Height);
    } completion:^(BOOL finished) {
    }];
    __weak typeof(self) weakSelf = self;
    __weak TDChooseCarC *weakChooseCar= chooseCar;
    chooseCar.chooseCarModelBlock = ^(TDChooseSelectedModel *selCarModel, NSIndexPath *leftSelIndexPath, NSIndexPath *rightSelIndexPath) {
        [UIView animateWithDuration:0.3f animations:^{
            weakChooseCar.view.frame = CGRectMake(0, Height, Width, Height);
        } completion:^(BOOL finished) {
            [weakChooseCar removeFromParentViewController];
            [weakChooseCar.view removeFromSuperview];
        }];
        weakSelf.selCarModel = selCarModel;
        weakSelf.leftSelCarIndex = leftSelIndexPath;
        weakSelf.rightSelCarIndex = rightSelIndexPath;
        NSString *tmpStr = [NSString stringWithFormat:@"%@%@",[HelpObject changeNull:selCarModel.brandnm],[HelpObject changeNull:selCarModel.seriesnm]];
        weakSelf.selCarDesStr = [HelpObject isBlankString:tmpStr] ? @"车型" : tmpStr;
        if (![HelpObject isBlankString:tmpStr]) {
            weakSelf.historyStr = @"";
            weakSelf.tf_search.text = @"";
        }
        [weakSelf loadNetData];
        [weakSelf setTopTitleArray];
        weakSelf.carSourceListHeadView.titleArray = weakSelf.titleArray;
        [weakSelf setTopSelHiden];
    };
    chooseCar.chooseCarCloseBtnClickBlock = ^{
        [UIView animateWithDuration:0.3f animations:^{
            weakChooseCar.view.frame = CGRectMake(0, Height, Width, Height);
        } completion:^(BOOL finished) {
            [weakChooseCar removeFromParentViewController];
            [weakChooseCar.view removeFromSuperview];
        }];
    };
}

// MARK: - 选择门店----
- (void)chooseStore {
    TDSearchStoreC *searchStoreC = [[TDSearchStoreC alloc] init];
    
    searchStoreC.tf_search_str = self.tf_search.text;
    searchStoreC.locationModel = self.locationModel;
    searchStoreC.selCarModel = self.selCarModel;
    searchStoreC.selDateModel = self.selDateModel;
//    searchStoreC.selStoreModel = self.selStoreModel;//这样写逻辑有问题  选择哪个就把哪个清空---------
    
    __weak typeof(self) weakSelf = self;
    searchStoreC.chooseStoreModelBlock = ^(TDSearchStoreSelModel *searchStoreSelModel, NSIndexPath *searchStoreLeftIndex, NSIndexPath *searchStoreRightIndex) {
        NSString *tmpShowStoreName = [NSString stringWithFormat:@"%@",[HelpObject changeNull:searchStoreSelModel.searchStoreModel.storename]];
        weakSelf.selStoreDesStr = [HelpObject isBlankString:tmpShowStoreName] ? @"门店" : tmpShowStoreName;
        [weakSelf setTopTitleArray];
        weakSelf.carSourceListHeadView.titleArray = weakSelf.titleArray;
        [weakSelf setTopSelHiden];
        [weakSelf loadNetData];
    };
    [self.navigationController pushViewController:searchStoreC animated:YES];
}

// MARK: - 选择日期--------
- (void)chooseDate {
    __weak typeof(self) weakSelf = self;
    TDriveCarDatePicker *driveCarDatePicker = [[TDriveCarDatePicker alloc] init];
    
    driveCarDatePicker.tf_search_str = self.tf_search.text;
    driveCarDatePicker.locationModel = self.locationModel;
    driveCarDatePicker.selModel = self.selCarModel;
//    driveCarDatePicker.dateSelModel = self.selDateModel;
    driveCarDatePicker.selStoreModel = self.selStoreModel;
    
    __weak TDriveCarDatePicker *weakDriveCarDatePicker= driveCarDatePicker;
    driveCarDatePicker.pickerViewCancleBtnBlock = ^{
        [UIView animateWithDuration:0.3f animations:^{
            weakDriveCarDatePicker.view.frame = CGRectMake(0, Height, Width, Height);
        } completion:^(BOOL finished) {
            [weakDriveCarDatePicker removeFromParentViewController];
            [weakDriveCarDatePicker.view removeFromSuperview];
        }];
    };
    driveCarDatePicker.pickerViewSureBtnBlock = ^(TDDriveCarDatePickerSelModel *selDateModel) {
        weakSelf.selDateModel = selDateModel;
        [UIView animateWithDuration:0.3f animations:^{
            weakDriveCarDatePicker.view.frame = CGRectMake(0, Height, Width, Height);
        } completion:^(BOOL finished) {
            [weakDriveCarDatePicker removeFromParentViewController];
            [weakDriveCarDatePicker.view removeFromSuperview];
        }];
//        NSString *tmpDateStr = [HelpObject changeNull:selDateModel.dateStr];
//        NSString *duraion = [HelpObject changeNull:selDateModel.timeDurationStr];
//        NSString *tmpStr = [NSString stringWithFormat:@"%@ %@天",tmpDateStr,duraion];
        weakSelf.selDateDesStr = [HelpObject isBlankString:selDateModel.showDateStr] ? @"日期" : selDateModel.showDateStr;
        [weakSelf setTopTitleArray];
        weakSelf.carSourceListHeadView.titleArray = weakSelf.titleArray;
        [weakSelf setTopSelHiden];
        [weakSelf loadNetData];
    };
    
    [self addChildViewController:driveCarDatePicker];
    [self.view addSubview:driveCarDatePicker.view];
    driveCarDatePicker.view.frame = CGRectMake(0, Height, Width, Height);
    
    [UIView animateWithDuration:0.3f animations:^{
        driveCarDatePicker.view.frame = CGRectMake(0, 0, Width, Height);
    } completion:^(BOOL finished) {
    }];
}

// MARK: - 排序按钮点击事件
- (void)paiXuBtnClick:(UIButton *)sender {
    PopoverView *popoverView = [PopoverView popoverView];
    popoverView.showShade = YES; // 显示阴影背景
    [popoverView showToView:sender withActions:[self setpaiXuActionArray]];
}

- (NSArray<PopoverAction *> *)setpaiXuActionArray {
    __weak typeof(self) weakSelf = self;
    NSMutableArray *actionMutaArray = [NSMutableArray array];
    NSArray *imageNameArray = @[@"综合",@"位置",@"价格",@"评价"];
    NSArray *selImageNameArray = @[@"综合sel",@"位置sel",@"价格sel",@"评价sel"];
    NSArray *titleArray = @[@"综合排序",@"离我最近",@"价格最低",@"最高评价"];
    // 综合排序 action
    for (int i = 0; i < titleArray.count; i++) {
        NSString *imageName = imageNameArray[i];
        NSString *title = titleArray[i];
        PopoverAction *action = [PopoverAction actionWithImage:[UIImage imageNamed:imageName] title:title handler:^(PopoverAction *action) {
#pragma mark - 该Block不会导致内存泄露, Block内代码无需刻意去设置弱引用.
            for (int selIndex = 0; selIndex < titleArray.count; selIndex++) {
                if ([title isEqualToString:titleArray[selIndex]]) {
                    weakSelf.selIndex = selIndex;
                    [TDCarSourceAllMessageModel shareAllMessageModel].orders = [NSString stringWithFormat:@"%d",selIndex + 1];
                    [weakSelf loadNetData];
                }
            }
        }];
        [actionMutaArray addObject:action];
    }
    for (int i = 0; i < selImageNameArray.count; i++) {
        PopoverAction *action = actionMutaArray[i];
        action.isSelect = NO;
        action.selImageName = selImageNameArray[i];
    }
    PopoverAction *selAction = actionMutaArray[self.selIndex];
    selAction.isSelect = YES;
    return actionMutaArray;
}

- (void)setBtnColor:(UIButton *)btn {
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    btn.layer.cornerRadius = 5;
    btn.clipsToBounds = YES;
}


- (void)setupTableView {
    _tableView.contentInset = UIEdgeInsetsMake(86, 0, 0, 0);
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"TDSearchCarListCell" bundle:nil] forCellReuseIdentifier:@"TDSearchCarListCellId"];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 340;
    __weak typeof(self) weakSelf = self;
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        [weakSelf loadMoreNetData];
    }];
}


#pragma mark - 实现数据源方法
#pragma mark - 返回组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

#pragma mark - 返回行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.carListArray.count;
}

#pragma mark - 返回每行内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //自定义cell
    TDSearchCarListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TDSearchCarListCellId" forIndexPath:indexPath];
    cell.indexPath = indexPath;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    TDCarSourceListModel *listModel = self.carListArray[indexPath.row];
    cell.carListModel = listModel;
    __weak typeof(self) weakSelf = self;
    cell.searchCarListCellBlock = ^(NSIndexPath *indexPath) {
        [weakSelf tableView:weakSelf.tableView didSelectRowAtIndexPath:indexPath];
    };
    //返回
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    TDCarDetailC *detailCarC = [[TDCarDetailC alloc] init];
    detailCarC.locationModel = _locationModel;
    TDCarSourceListModel *carSourceListModel = self.carListArray[indexPath.row];
    detailCarC.carSourceListModel = carSourceListModel;
    detailCarC.selDateModel = self.selDateModel;
    [self.navigationController pushViewController:detailCarC animated:YES];
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    TDCarSourceSectionHeadView *carSourceSectionHeadView = [TDCarSourceSectionHeadView carSourceSectionHeadView];
    carSourceSectionHeadView.frame = CGRectMake(0, 0, Width, 60);
    self.carSourceSectionHeadView = carSourceSectionHeadView;
    [carSourceSectionHeadView.btn_sel addTarget:self action:@selector(paiXuBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self setTopSelHiden];
    [self setTopHeadTitle];
    return carSourceSectionHeadView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (([self.selCarDesStr isEqualToString:@"车型"] && [self.selDateDesStr isEqualToString:@"日期"] && [self.selStoreDesStr isEqualToString:@"门店"] && [HelpObject isBlankString:_tf_search.text]) || self.carListArray.count == 0) {
        return 10;
    } else {
        return 60;
    }
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    return;
    NSInteger height = 66;
    if (KIsiPhoneX) {
        return;
    }
    if (_historyOffY<scrollView.contentOffset.y)
    {
//        KIsiPhoneX
        
        NSLog(@"%.2f",scrollView.contentOffset.y);
        //表示是向上滑动
        //隐藏
        if (scrollView.zl_height + scrollView.contentOffset.y >= scrollView.contentSize.height || scrollView.contentOffset.y <= -height) {
            return;
        }
        CGFloat offsetY = scrollView.contentOffset.y - _historyOffY;
        if (_carSourceListHeadView.zl_y > 5) {
            _carSourceListHeadView.zl_y = _carSourceListHeadView.zl_y - fabs(offsetY);

        }else {
            _carSourceListHeadView.zl_y = 5;
        }
        
        //        [UIView animateWithDuration:0.25 animations:^{
        //            _redView.zl_height = 0;
        //        }];
    }
    else if(_historyOffY>scrollView.contentOffset.y)
    {
        NSLog(@"%.2f",scrollView.contentOffset.y);
        
        if (scrollView.zl_height + scrollView.contentOffset.y >= scrollView.contentSize.height || scrollView.contentOffset.y <= -height) {
            return;
        }
        //表示是向下面滑动
        CGFloat offsetY = scrollView.contentOffset.y - _historyOffY;
        //显示
        if (_carSourceListHeadView.zl_y < height + 5) {
            _carSourceListHeadView.zl_y = _carSourceListHeadView.zl_y + fabs(offsetY);
        }else {
            _carSourceListHeadView.zl_y = height + 5;
        }
    }
    _historyOffY=scrollView.contentOffset.y;
}



// MARK: - 加载数据
- (void)loadData {
    [self loadLocalData];
    [self loadNetData];
}
// MARK: - 本地数据
- (void)loadLocalData {
    self.selIndex = 0;
    self.selCarDesStr = @"车型";
    self.selDateDesStr = @"日期";
    self.selStoreDesStr = @"门店";
    [self setTopTitleArray];
    self.tf_search.text = [HelpObject isBlankString:_historyStr] ? @"" : _historyStr;
    [TDCarSourceAllMessageModel shareAllMessageModel].orders = @"1";
}


- (void)setTopTitleArray {
    self.titleArray = [NSMutableArray array];
    [self.titleArray addObject:self.selCarDesStr];
    [self.titleArray addObject:self.selDateDesStr];
    [self.titleArray addObject:self.selStoreDesStr];
}

// MARK: - 设置顶部的按钮隐藏----------
- (void)setTopSelHiden {
    if (([self.selCarDesStr isEqualToString:@"车型"] && [self.selDateDesStr isEqualToString:@"日期"] && [self.selStoreDesStr isEqualToString:@"门店"] && [HelpObject isBlankString:_tf_search.text]) || self.carListArray.count == 0) {
        self.carSourceSectionHeadView.lbe_source.hidden = YES;
        self.carSourceSectionHeadView.btn_sel.hidden = YES;
    } else {
        self.carSourceSectionHeadView.lbe_source.hidden = NO;
        self.carSourceSectionHeadView.btn_sel.hidden = NO;
    }
}

- (void)setTopHeadTitle {
    self.carSourceSectionHeadView.lbe_source.text = [NSString stringWithFormat:@"%@个车源",self.totalCarNum];
}

// MARK: - 关闭按钮点击事件-------
- (IBAction)closeBtnClick:(UIButton *)sender {
    if (self.navigationController.childViewControllers.count > 1) {
       [self.navigationController popViewControllerAnimated:YES];
    }else {
       [self dismissViewControllerAnimated:YES completion:nil];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)searchBtnClick:(UIButton *)sender {
    TDSearchCarController *searchCarC = [[TDSearchCarController alloc] init];
    __weak typeof(self) weakSelf = self;
    searchCarC.searchCarCBlock = ^(NSString *historyStr) {
        weakSelf.historyStr = historyStr;
        weakSelf.tf_search.text = [HelpObject isBlankString:weakSelf.historyStr] ? @"" : weakSelf.historyStr;
        if (![HelpObject isBlankString:weakSelf.historyStr]) {
            weakSelf.selCarModel = nil;
            weakSelf.leftSelCarIndex = nil;
            weakSelf.rightSelCarIndex = nil;
            [TDCarSourceAllMessageModel shareAllMessageModel].carsourceSelCarModel = nil;
            weakSelf.selCarDesStr = @"车型";
            [weakSelf setTopTitleArray];
            weakSelf.carSourceListHeadView.titleArray = weakSelf.titleArray;
            [weakSelf setTopSelHiden];
        }
        [weakSelf loadNetData];
    };
    [self presentViewController:searchCarC animated:YES completion:nil];
}



// MARK: - 获取网络数据-----
- (void)loadNetData {
    self.carSourceSectionHeadView.lbe_source.hidden = YES;
    self.carSourceSectionHeadView.btn_sel.hidden = YES;
    // MARK: - 获取车源列表--------------
    if (!_locationModel) {
        self.noticeText = @"定位失败,请稍后重试";
        return;
    }
    if ([HelpObject isBlankString:[AppSetting shareAppSetting].topcompanyid]) {
        self.noticeText = @"顶级公司id为空";
        return;
    }
    self.selStoreModel = [TDCarSourceAllMessageModel shareAllMessageModel].carsourceSelStoreModel;
    NSString *topcompanyid = [AppSetting shareAppSetting].topcompanyid;
    NSMutableDictionary *parDic = @{@"topcompanyid":topcompanyid,
                             @"longitude":_locationModel.longitude,
                             @"latitude":_locationModel.latitude,
                             @"prevrows":@"0",
                             @"showrows":rowNum,
                             }.mutableCopy;
    [self setParaDic:parDic];
    __weak typeof(self) weakSelf = self;
    [self progressHUDShowWithText:nil];
    [NetWorkRequest postNetRequestData:CarListTD parmeters:parDic response:^(NSDictionary *response) {
        if (response) {
            [weakSelf progressHUDHideImmediately];
            
            weakSelf.carListArray = [NSArray yy_modelArrayWithClass:[TDCarSourceListModel class] json:response[@"data"][@"carlist"]].mutableCopy;
            weakSelf.totalCarNum = [HelpObject changeNull:response[@"data"][@"total"]];
            [weakSelf.tableView reloadData];
            [weakSelf.carSourceListHeadView makeConstraints:^(MASConstraintMaker *make) {
                make.leading.offset(0);
                make.topMargin.offset(51);
                make.width.offset(Width);
                make.height.offset(66);
            }];
            weakSelf.carSourceListHeadView.titleArray = weakSelf.titleArray;
            [weakSelf setTopHeadTitle];
        }else {
            [weakSelf progressHUDHideImmediately];
        }
    } netError:^(NSError *error) {
        [weakSelf progressHUDShowWithCompleteText:nil isSucceed:NO];
    }];
}



// MARK: - 获取网络数据-----
- (void)loadMoreNetData {
    // MARK: - 获取车源列表--------------
    if (!_locationModel) {
        self.noticeText = @"定位失败,请稍后重试";
        return;
    }
    if ([HelpObject isBlankString:[AppSetting shareAppSetting].topcompanyid]) {
        self.noticeText = @"顶级公司id为空";
        return;
    }
    //取出上一个模型--------
    NSString *prevrows = @"0";
    if (self.carListArray && self.carListArray.count != 0 ) {
        TDCarSourceListModel *lastModel = self.carListArray.lastObject;
        prevrows = lastModel.rowno;
    }
    NSString *topcompanyid = [AppSetting shareAppSetting].topcompanyid;
    NSMutableDictionary *parDic = @{@"topcompanyid":topcompanyid,
                             @"longitude":_locationModel.longitude,
                             @"latitude":_locationModel.latitude,
                             @"prevrows":prevrows,
                             @"showrows":rowNum
                             }.mutableCopy;
    [self setParaDic:parDic];
    __weak typeof(self) weakSelf = self;
    [self progressHUDShowWithText:nil];
    [NetWorkRequest postNetRequestData:CarListTD parmeters:parDic response:^(NSDictionary *response) {
        [weakSelf.tableView.mj_footer endRefreshing];
        if (response) {
            [weakSelf progressHUDHideImmediately];
            NSArray *tmpArray = [NSArray yy_modelArrayWithClass:[TDCarSourceListModel class] json:response[@"data"][@"carlist"]];
            if (!tmpArray || tmpArray.count == 0) {
                weakSelf.noticeText = @"暂无更多数据";
                return;
            }
            [weakSelf.carListArray addObjectsFromArray:tmpArray];
            [weakSelf.tableView reloadData];
            self.carSourceListHeadView.titleArray = self.titleArray;
            
        }else {
            [weakSelf progressHUDHideImmediately];
        }
    } netError:^(NSError *error) {
        [weakSelf progressHUDShowWithCompleteText:nil isSucceed:NO];
        [weakSelf.tableView.mj_footer endRefreshing];
    }];
}

- (void)setParaDic:(NSMutableDictionary *)paraDic {
    
    NSString *tmpWorkdayf = [_selDateModel.yearStr stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
    NSString *tmpWorkdayT = [_selDateModel.yearEndStr stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
    
    [paraDic setValue:[HelpObject changeNull:tmpWorkdayf] forKey:@"workdayf"];
    [paraDic setValue:[HelpObject changeNull:tmpWorkdayT] forKey:@"workdayt"];
    [paraDic setValue:[HelpObject changeNull:_selStoreModel.searchStoreModel.storeid] forKey:@"storeid"];
    
    [paraDic setValue:[HelpObject changeNull:_selCarModel.brandid] forKey:@"brandid"];
    
    [paraDic setValue:[HelpObject changeNull:_tf_search.text] forKey:@"cartype"];
    [paraDic setValue:[HelpObject changeNull:_selCarModel.seriesid] forKey:@"seriesid"];
    [paraDic setValue:[TDCarSourceAllMessageModel shareAllMessageModel].orders forKey:@"orders"];
}

@end
